using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using ZoeEngine;
using ZoeEngine.Components.Physics;
using ZoeEngine.Components.Graphics;
using ZoeEngine.Components.Controllers;
using ZoeEngine.Framework;
using ZoeEngine.Framework.Collision;


namespace StrikeTheEarth
{
    public class Core : Microsoft.Xna.Framework.Game
    {
        public Core()
        {
            GraphicsDeviceManager gdm = new GraphicsDeviceManager(this);

            Zoe.Boot(this);

            Zoe.DEBUG_MODE = DebugMode.PHYSICS;

            this.IsMouseVisible = true;
            this.Window.Title = "Strike the Earth - A Mining Simulator";
        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        protected override void Initialize()
        {
            base.Initialize();

            Entity e = Zoe.CreateEntity();

            PhysBodyComponent pbc = new PhysBodyComponent();
            pbc.Position = new Vector2(200.0f, 20.0f);
            
            PhysCircle pc = new PhysCircle(30.0f);
            pc.Friction = float.MaxValue;
            
            pbc.CollisionShapes.Add(pc);
            pbc.CollisionType = CollisionType.Dynamic;

            e.Add(pbc);

            Entity f = Zoe.CreateEntity();

            PhysBodyComponent pbcc = new PhysBodyComponent();
            pbcc.Position = new Vector2(210.0f);
            pbcc.CollisionShapes.Add(new PhysRectangle(200.0f, 50.0f));
            pbcc.CollisionType = CollisionType.Static;

            f.Add(pbcc);

            Entity q = Zoe.CreateEntity();

            PhysBodyComponent pbccc = new PhysBodyComponent();
            pbccc.Position = new Vector2(200.0f, -10.0f);
            pbccc.CollisionShapes.Add(new PhysRectangle(60.0f, 60.0f));
            pbccc.CollisionType = CollisionType.Dynamic;
            pbccc.FixedRotation = true;

            PhysWheelJoint pwj = new PhysWheelJoint(pbc);
            pwj.Anchor = pbc.Position;
            pwj.MotorEnabled = true;

            SpriteRenderComponent src = new SpriteRenderComponent("Textures\\WalkAtlas");
            src.FrameSize = new Point(104, 151);

            AnimationController ac = new AnimationController();
            ac.Animations.Add("PLAYER_WALK_RIGHT", new AnimationData { firstFrame = 0, lastFrame = 5, frameTime = 300 });
            ac.Animations.Add("PLAYER_WALK_LEFT", new AnimationData { firstFrame = 6, lastFrame = 11, frameTime = 300 });
            ac.Animations.Add("PLAYER_IDLE_RIGHT", new AnimationData { firstFrame = 12, lastFrame = 12, frameTime = 300 });
            ac.Animations.Add("PLAYER_IDLE_LEFT", new AnimationData { firstFrame = 13, lastFrame = 13, frameTime = 300 });
            ac.PlayAnimation("PLAYER_IDLE_RIGHT");

            PlatformerKeyboardController pkc = new PlatformerKeyboardController();

            q.Add(pbccc);
            q.Add(pwj);
            q.Add(src);
            q.Add(ac);
            q.Add(pkc);

        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
    }
}
